var status = -1;
var typed = 0;
var transId = 4031997;

function start() {
    action(1, 0, 0)
}

function action(g, d, c) {
    if (g == 1) {
        status++
    } else {
        if (status >= 0) {
            cm.dispose();
            return
        }
        status--
    }
    if (status == 0) {
        var f = "亲爱的#b#e#h ##n#k，欢迎来到点卷中介所，需要什么帮助吗？\r\n\r\n";
        f += "\t当前点卷余额：#r" + cm.getPlayer().getCSPoints(1) + "#k点\r\n";
        f += "\t当前#t" + transId + "#数量：#r" + cm.getItemQuantity(transId) + "#k个\r\n\r\n";
        f += "#b#L3#了解点卷中介说明#l\r\n";
        f += "#L1#兑换点卷#l\r\n";
        f += "#L2#兑换蘑菇金币#l\r\n";
        cm.askMenu(f)
    } else {
        if (status == 1) {
            typed = c;
            if (c == 3) {
                status = -1;
                cm.askMenu("1个#b#t" + transId + "##k可以兑换#r800点卷#k，#r1000点卷#k可以兑换1个#b#t" + transId + "##k。#b#t" + transId + "##k可用于玩家之间的交易与贩售。")
            } else {
                if (c == 1) {
                    var h = cm.getItemQuantity(transId);
                    cm.askNumber("#d#e<中介币兑换点卷>#n#k\r\n当前最多可以兑换#r" + (h * 800) + "#k点卷，最多输入#r" + h + "#k。\r\n请输入兑换的#b#t" + transId + "##k数量:\r\n兑换比例为 1 : 800\r\n", 1, 1, h)
                } else {
                    if (c == 2) {
                        var h = Math.floor(cm.getPlayer().getCSPoints(1) / 1000);
                        if (h > 300) {
                            h = 300
                        }
                        cm.askNumber("#d#e<点卷兑换中介币>#n#k\r\n本次最多可以兑换#r" + h + "#k个#b#t" + transId + "##k\r\n请输入兑换的#b#t" + transId + "##k数量:\r\n兑换比例为 1000 : 1\r\n", 1, 1, h)
                    }
                }
            }
        } else {
            if (status == 2) {
                var e = Math.floor(c);
                if (e <= 0) {
                    cm.sendOk("Error");
                    cm.dispose();
                    return
                }
                if (typed == 1) {
                    if (cm.haveItem(transId, e)) {
                        status = -1;
                        var a = 800 * e;
                        cm.gainItem(transId, -e);
                        cm.getPlayer().modifyCSPoints(1, a);
                        cm.askMenu("成功兑换了#r" + a + "#k点卷")
                    } else {
                        cm.sendOk("你好像没有那么多#b#t" + transId + "##k哦！");
                        cm.dispose()
                    }
                } else {
                    if (typed == 2) {
                        if (cm.getSpace(4) < 1) {
                            status = -1;
                            cm.askMenu("您的背包空间不足，请整理背包中其他栏的空间。")
                        } else {
                            var b = e * 1000;
                            if (cm.getPlayer().getCSPoints(1) >= b) {
                                status = -1;
                                cm.gainItem(transId, e);
                                cm.getPlayer().modifyCSPoints(1, -b);
                                cm.askMenu("成功兑换了#r" + e + "#k个中介币")
                            } else {
                                cm.sendOk("你好像没有那么多点卷哦！");
                                cm.dispose()
                            }
                        }
                    }
                }
            }
        }
    }
};